/*------------------------------------------------------------------------------
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
--------------------------------------------------------------------------------
This program was written for Afflatus Techtronics - Resource section.

File                : bsp.h
Code type	        : Board Support Package for 4K-main

Controllers	        : PIC18F468x
Compiler and IDE	: MCC18 with MPLab IDE

Author  			: Ashwin Vijayakumar
Current Occupation  : Computer Engineering Graduate student @ WMU, Kalamazoo
                          , Michigan

Start Date			: Jan-27-2011
Validation Date    	: Jan-27-2011

--------------------------------------------------------------------------------
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
------------------------------------------------------------------------------*/

#include <p18cxxx.h>

/**@cond -----------------------------------------------------------------------
 * typedef section (Project scope)
 * Add typedef's with project scope here.
 * Capitalization: Upper_Camel_Case.
 * ----------------------------------------------------------------- @endcond */

/* Device ID */
/**
 * @brief Device ID.
 * @details This enum shall be used to list all available devices/peripherals
 * on this board.
 */
typedef enum
{
  MCAL_DEVICE_ID_UART0,         /**< Device ID for UART0. */
  PAL_DEVICE_ID_CLCD0           /**< Device ID for character LCD0. */
} Bsp_DeviceIdType;

// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Oscillator Configuration ~~~~~~~~~~~~
// -----------------------------------------------------------------------------

#define FOSC_8MHZ	OSCCON |= 0x70;		// IRCF[2:0] = 111 for Max Fre (8MHz)

/* Internal EEPROM size (see EEP.h) */
#define EEP_V3
// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Oscillator Configuration ~~~~~~~~~~~~
// -----------------------------------------------------------------------------


// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Board initialization ~~~~~~~~~~~~~~~~
// -----------------------------------------------------------------------------

#define BOARD_Initialize()	\
					FOSC_8MHZ;\
					LED_Initialize();\
					SW_Initialize();

// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// LED routines ~~~~~~~~~~~~~~~~~~~~~~~~
// -----------------------------------------------------------------------------

#define LED_Initialize()	\
					ADCON1bits.PCFG3 = 1;\
					ADCON1bits.PCFG2 = 0;\
					ADCON1bits.PCFG1 = 1;\
					ADCON1bits.PCFG0 = 0;\
					CMCONbits.CM2 = 1;\
					CMCONbits.CM1 = 1;\
					CMCONbits.CM0 = 1;\
					TRISEbits.TRISE0 = 0;\
					TRISEbits.TRISE1 = 0;\
					TRISEbits.TRISE2 = 0;\
					LATEbits.LATE0 = 0;\
					LATEbits.LATE1 = 0;\
					LATEbits.LATE2 = 0;

#define LED0_ON()	PORTEbits.RE0 = 1;	// Turn ON RE0 [LED0]
#define LED1_ON()	PORTEbits.RE1 = 1;	// Turn ON RE1 [LED1]
#define LED2_ON()	PORTEbits.RE2 = 1;	// Turn ON RE2 [LED2]

#define LED0_OFF()	PORTEbits.RE0 = 0;	// Turn OFF RE0 [LED0]
#define LED1_OFF()	PORTEbits.RE1 = 0;	// Turn OFF RE1 [LED1]
#define LED2_OFF()	PORTEbits.RE2 = 0;	// Turn OFF RE2 [LED2]

// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// LED routines ~~~~~~~~~~~~~~~~~~~~~~~~
// -----------------------------------------------------------------------------


// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Switch routines ~~~~~~~~~~~~~~~~~~~~~
// -----------------------------------------------------------------------------

#define SW_Initialize()	\
					ADCON1bits.PCFG3 = 1;\
					ADCON1bits.PCFG2 = 0;\
					ADCON1bits.PCFG1 = 1;\
					ADCON1bits.PCFG0 = 1;\
					TRISAbits.TRISA4 = 1;\
					TRISAbits.TRISA5 = 1;\
					LATAbits.LATA4 = 1;\
					LATAbits.LATA5 = 1;

#define SW0			PORTAbits.RA4		// Check if 0/1
#define SW1			PORTAbits.RA5		// Check if 0/1

// -----------------------------------------------------------------------------
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Switch routines ~~~~~~~~~~~~~~~~~~~~~
// -----------------------------------------------------------------------------
